//
//  MyView.m
//  Demo
//
//  Created by Admin on 16/8/5.
//  Copyright © 2016年 Admin. All rights reserved.
//

#import "MyView.h"

@interface MyView ()
{
    UIButton *bu;
}

@end

@implementation MyView

-(instancetype)initWithArr:(NSArray*)arr Bol:(BOOL)bol{
    self  = [super init];
    if (self) {
        self.frame = CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 40);
        self.backgroundColor = [UIColor colorWithWhite:0.902 alpha:1.000];
        NSInteger t = arr.count;
        for (int i = 0; i< t; i++) {
            UIButton * ui = [UIButton buttonWithType:UIButtonTypeCustom];
            ui.titleLabel.font = [UIFont systemFontOfSize: 14.0];            ui.frame = CGRectMake(self.bounds.size.width/t*i, 0, self.bounds.size.width/t, 40);
            ui.tag = 1000 + i;
            [ui setTitle:arr[i] forState:UIControlStateNormal];
            [ui addTarget:self action:@selector(buttAction:) forControlEvents:UIControlEventTouchUpInside];
            if (i == 0) { // 默认展示第二组数据
                [ui setTitleColor:[UIColor colorWithRed:1.000 green:0.800 blue:0.400 alpha:1.000] forState:UIControlStateNormal];
                bu = ui;
            }else{
                [ui setTitleColor:[UIColor colorWithWhite:0.498 alpha:1.000] forState:UIControlStateNormal];
            }
            [self addSubview:ui];
        }
        if (bol) {
            for (int i = 1 ; i < t  ; i++) {
                UIView *linV = [[UIView alloc] initWithFrame:CGRectMake(self.bounds.size.width/t*i, 10, 1, 20)];
                linV.backgroundColor = [UIColor colorWithWhite:0.800 alpha:1.000];
                [self addSubview:linV];
            }
        }
        
    } return self;
}

-(void)buttAction:(UIButton*)but{
//    NSLog(@"--- %ld",but.tag);
    [bu setTitleColor:[UIColor colorWithWhite:0.498 alpha:1.000] forState:UIControlStateNormal];
    [but setTitleColor:[UIColor colorWithRed:1.000 green:0.800 blue:0.400 alpha:1.000] forState:UIControlStateNormal];
    bu = but;
    [self.delget buttonAction:bu];

    
    
}

@end
